package com.quanyan.comment.sensitive.util;

import java.util.ArrayList;
import java.util.List;

public class CharToken {
	public static List<String> useDFA(String str, char chat) {
		List<String> codes = new ArrayList<String>();
		Status currentState = null;
		char c1 = '\0';
		char c2 = '\0';
		for (int i = 0; i < str.length(); i++) {
			char currentChar = str.charAt(i);
			if (currentChar == chat) {
				if (currentState == Status.SECOND) {
					char[] s1 = { c1, c2 };
					codes.add(new String(s1));
				}
				currentState = Status.DONE;
			} else if (currentState == Status.DONE) {
				c1 = currentChar;
				currentState = Status.FIRST;
			} else if (currentState == Status.FIRST) {
				c2 = currentChar;
				currentState = Status.SECOND;
			} else if (currentState == Status.SECOND) {
				char[] s1 = { c1, c2 };
				codes.add(new String(s1));
				currentState = null;
			}
		}
		if (currentState == Status.SECOND) {
			char[] s1 = { c1, c2 };
			codes.add(new String(s1));
		}
		return codes;
	}

	public enum Status {
		DONE, FIRST, SECOND;
	}
}
